package crontab

import (
	"longmen/server/config/global"
	"longmen/server/pkg/db/mysql/db_sports"
	"time"
)

func SyncExpert() {
	list, err := db_sports.QueryExpertPlanFeeList(time.Now().Unix())
	if err == nil {
		for _, expertPlan := range list {
			commitCumSumExpertPlan(expertPlan.Id, expertPlan.IsWin)
		}
	}
}

/**
* @Author:admin
* @Description:
* @Param :
* @Return :
* @Date: 14:29 2022/6/20
 */
func commitCumSumExpertPlan(id int64, isWin int32) error {
	//开始事务
	session := global.GetX().Begin()
	//更新记录
	if db_sports.UpdateExpertPlan(id, session) == 0 {
		session.Rollback()
		return nil
	}
	if db_sports.UpdateExpertSummary(id, isWin, session) == 0 {
		session.Rollback()
		return nil
	}
	if err := session.Commit().Error; err != nil {

		return nil
	}
	return nil
}
